Loaded Dice Example

FILE: Loaded.cln

Introduction

The Random Generator object is a good source of random numbers, with an even distribution, one number just as likely as another. When analysing a model you occasionally need weighted randomness, where some numbers are more likely than others.

This file is an example of a weighted 6 sided dice. A table of weightings gives the relative likelihood of each face on the dice appearing, a random object provides the randomness and the rest of the sheet calculates a resultant face 1 to 6.

To use this sheet, switch on automatic recalculation and click on the Random Generator object to roll the dice.

There are 6 entries in the weighting table, if you want a 20 sided dice, simply enlarge the column to 20 entries.


This is an Input Table object, it inputs the table of weightings as a column array. Notice that the values are relative weighting, {10,10,10,10,10,10} would produce a balanced dice, but then again, so would {1,1,1,1,1,1}.


This is a General Toolbox Object, the function we are using from this object is the Rolling sum, in this case it converts {{1,3,5,6,4,2}} into the array {{1,4,9,15,19,21}}.


This is a Computer Object. It is used to search the weightings to find the interval containing the random result.

The program it contains is shown below.

main{

for (i:=0; i<size(b[0]); i+=1;) {

if (b[0][i] >a) return (i+1);

};

};


This For loop, goes through the elements of the first column of b.

b[0]	Is the first column in input b

size(b[0])	is the number of elements in that column


This IF statement checks if element i, of column 0, of input b is greater than the random number. If it is then it returns i+1;

If you consider a typical example:

b is {{1,4,9,15,19,21}}

a is 16.5

Therefore the random number a lies in the interval between 15 and 19 of b, which corresponds to face 5 on the dice.


This is a Random Generator object, here it is set to return random numbers 0 upto 1. To change the random number, click on this object.


This is a Calculator Object. The equation in this object is b*sum(a).

b	Is the random number 0 to 1

a	Is the array of weightings

sum(a)	Is the total of the weightings added together

This equation scales the random number to be from 0 to 21.


This is an Output Table, used to display the result of the rolled dice.